//
//  ForMoneyView.m
//  项目三
//
//  Created by rimi on 15/10/9.
//  Copyright (c) 2015年 rimi. All rights reserved.
//

#import "ForMoneyView.h"
#import "CollectView.h"

@interface ForMoneyView () <UITextFieldDelegate> {

    CollectView *_colletView;
}

@end

@implementation ForMoneyView
#pragma mark - init
- (id)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self initializeUserInterface];
    }
    return self;
}

- (void)initializeUserInterface {
    
    self.backgroundColor = COLOR(205, 205, 205, 1);
    [self addSubview:self.btn];
    [self addSubview:self.searchImageView];
    [self addSubview:self.searchField];
}
#pragma mark - privte methods
- (void)respondsToSaveBtnEvent:(UIButton *)sender {
    if (!_colletView) {
        _colletView = [[CollectView alloc] init];
    }
    if (![self.subviews containsObject:_colletView]) {
        [self addSubview:_colletView];
    }
}
- (void)textFieldDidBeginEditing:(UITextField *)textField {

    
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self endEditing:YES];
}
#pragma mark - getter
- (UIButton *)btn {
    if (!_btn) {
        _btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_btn setFrame:DHFlexibleFrame(CGRectMake(39, 13, 105, 36))];
        [_btn setBackgroundImage:[UIImage imageNamed:@"我的收藏"] forState:UIControlStateNormal];
        [_btn addTarget:self action:@selector(respondsToSaveBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn;
}
- (UIImageView *)searchImageView {

    if (!_searchImageView) {
        _searchImageView = [[UIImageView alloc] initWithFrame:DHFlexibleFrame(CGRectMake(369, 16, 300, 32))];
        _searchImageView.image = [UIImage imageNamed:@"高级搜索"];
    }
    return _searchImageView;
}
- (UITextField *)searchField {

    if (!_searchField) {
        _searchField = [[UITextField alloc] initWithFrame:DHFlexibleFrame(CGRectMake(430, 18, 240, 32))];
        _searchField.placeholder = @"请输入名称或者编号搜索";
        _searchField.textColor = [UIColor blackColor];
        _searchField.adjustsFontSizeToFitWidth = YES;
        _searchField.borderStyle = UITextBorderStyleNone;
        _searchField.delegate = self;
        _searchField.clearsOnBeginEditing = YES;
        _searchField.clearButtonMode = UITextFieldViewModeWhileEditing;
    }
    return _searchField;
}

@end
